﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace KingOfCSharp.iHunter.Plugins
{
    public partial class FilterConfigureControl : UserControl, System.Xml.Serialization.IXmlSerializable
    {
        private XmlDocument settings;

        public FilterConfigureControl()
        {
            settings = new XmlDocument();
            settings.Load("configure.ini");
            InitializeComponent();
        }

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            settings.Load(reader);
            strengthBox.Text = settings.DocumentElement["Strength"].InnerText;
            filePathBox.Text = settings.DocumentElement["Model"].InnerText;
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            if (settings.DocumentElement["Strength"].InnerText == "" || settings.DocumentElement["Model"].InnerText == "")
            {
                throw new ArgumentException("Please input correct parameters.");
            }
            settings.WriteTo(writer);
        }

        #endregion

        private void applySettingButton_Click(object sender, EventArgs e)
        {
            // double strength = double.Parse(settings.DocumentElement["Strength"].InnerText);
            string filePath = settings.DocumentElement["Model"].InnerText;
            WriteXml(XmlWriter.Create(Directory.GetCurrentDirectory() + "\\" + filePath));
        }
    }
}
